﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shop.Core
{
    [Serializable]
    public abstract class BaseEntity<T>
    {
        public virtual T Id
        {
            get;
            set;
        }

        //public override bool Equals(object obj)
        //{
        //    return Equals(obj as BaseEntity<T>);
        //}
        ///// <summary>
        ///// 是否还未持久化
        ///// </summary>
        ///// <param name="obj"></param>
        ///// <returns></returns>
        //private static bool IsTransient(BaseEntity<T> obj)
        //{
        //    return obj != null && Equals(obj.Id, default(T));
        //}

        //public virtual bool Equals(BaseEntity<T> other)
        //{
        //    if (other == null)
        //        return false;

        //    if (ReferenceEquals(this, other))
        //        return true;

        //    if (!IsTransient(this) &&
        //        !IsTransient(other) &&
        //        Equals(Id, other.Id))
        //    {
        //        var otherType = other.GetType();
        //        var thisType = this.GetType();
        //        return thisType.IsAssignableFrom(otherType) ||
        //                otherType.IsAssignableFrom(thisType);
        //    }
        //    return false;
        //}

        //public override int GetHashCode()
        //{
        //    if (Equals(Id, default(T)))
        //        return base.GetHashCode();
        //    return Id.GetHashCode();
        //}

        //public static bool operator ==(BaseEntity<T> x, BaseEntity<T> y)
        //{
        //    return Equals(x, y);
        //}

        //public static bool operator !=(BaseEntity<T> x, BaseEntity<T> y)
        //{
        //    return !(x == y);
        //}
    }
}
